module.exports = {
    state: {
        train: {},
        lesson: {}
    },
    mutations: {
        train (state, data) {
            state.train = {
                list: data
            }
        },
        lesson (state, {id, data}) {
            state.lesson = {
                lesson: id,
                content: data
            }
        }
    },
    actions: {
        getTrain ({commit, state}, resolve) {
            $store.api.call('train_list', {
                message: '获取培训清单失败'
            }, ({data}) => {
                commit('train', data)
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        },
        getLesson ({commit, state}, {id, resolve}) {
            $store.api.call('train_lesson', {
                message: '获取培训课程失败',
                params: {id}
            }, ({data}) => {
                commit('lesson', {id, data})
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        },
        testSubmit ({commit, state}, {id, test, resolve}) {
            $store.api.call('train_test', {
                message: '提交考试失败',
                params: {
                    id
                },
                form: test
            }, ({data}) => {
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        }
    },
    getters: {
        trainList (state) {
            return state.train
        },
        trainLesson (state) {
            return state.lesson
        }
    }
}